package stack_and_queue;

import java.util.Stack;

public class 最小栈 {
    class MinStack {
        Stack<Integer> a,b;
        /** initialize your data structure here. */
        public MinStack() {
            a = new Stack<>();
            b = new Stack<>();
        }
        public void push(int x) {
            a.add(x);
            if(b.empty() || b.peek() >= x)
                b.add(x);
        }
/*
        public void push(int x) {
            if(!b.isEmpty() && x > b.peek()) {
                a.push(x);
            }else{
                b.push(x);
                a.push(x);
            }
        }
*/
        public void pop() {
            if(a.pop().equals(b.peek()))
                b.pop();
        }

        public int top() {
            return a.peek();
        }

        public int getMin() {
            return  b.peek();
        }
    }
}
